/*******************************************************
 *
模块描述: 继承线程类，读取按键驱动键值
版本号:  V1.0
时间:	2015-4-13 11:15:58
开发者:  深圳市华友高科有限公司，欧茂江

完成状态: 初步完成，需要实际测试验证,并非最终版!
使用方法: 请参照示例用法！

*******************************************************/


#ifndef THREADDEV_H
#define THREADDEV_H

#include <QObject>
#include <QThread>
#include <QReadWriteLock>
#include "devnamespace.h"
//#include <iostream>
//--------------------------------------------------
//这是读取键盘驱动键值的应用程序相关的头文件，不可删除！
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
//--------------------------------------------------

#define BUTTONS_DEV "/dev/event0"

#define LED_ALL 0xffffffff
#define LED_ON 0x1
#define LED_OFF 0x0


#define TEACHBOX_BUZZER	(0x80)
#define TEACHBOX_BUZZER_HQF	(0x8000)
#define TEACHBOX_BUZZER_HTA (0x80000000)
#define TEACHBOX_LED1		(0x1	)
#define TEACHBOX_LED2		(0x1<<1	)
#define TEACHBOX_LED3		(0x1<<2	)
#define TEACHBOX_LED4		(0x1<<3	)
#define TEACHBOX_LED5		(0x1<<4	)
#define TEACHBOX_LED6		(0x1<<5	)
#define TEACHBOX_LED7		(0x1<<6	)
#define TEACHBOX_LED8		(0x1<<7	)
#define TEACHBOX_LED9		(0x1<<8	)
#define TEACHBOX_LED10		(0x1<<9	)
#define TEACHBOX_LED11		(0x1<<10	)
#define TEACHBOX_LED12		(0x1<<11	)
#define TEACHBOX_LED13		(0x1<<12	)
#define TEACHBOX_LED14		(0x1<<13	)
#define TEACHBOX_LED15		(0x1<<14	)
#define TEACHBOX_LED16		(0x1<<15	)
#define TEACHBOX_LED17		(0x1<<16	)
#define TEACHBOX_LED18		(0x1<<17	)
#define TEACHBOX_LED19		(0x1<<18	)
#define TEACHBOX_LED20		(0x1<<19	)
#define TEACHBOX_LED21		(0x1<<20	)
#define TEACHBOX_LED22		(0x1<<21	)
#define TEACHBOX_LED23		(0x1<<22	)
#define TEACHBOX_LED24		(0x1<<23	)
#define TEACHBOX_LED25		(0x1<<24	)
#define TEACHBOX_LED26		(0x1<<25	)
#define TEACHBOX_LED27		(0x1<<26	)
#define TEACHBOX_LED28		(0x1<<27	)
#define TEACHBOX_LED29		(0x1<<28	)
#define TEACHBOX_LED30		(0x1<<29	)
#define TEACHBOX_LED31		(0x1<<30	)

class ThreadDev : public QThread
{
    Q_OBJECT
public:
    explicit ThreadDev(QObject *parent = 0);
    ~ThreadDev();


public slots:
    void setBuzzerPlay_slot();
    void setLed_slot(unsigned int led,unsigned char flag);
signals:
    void sendKeySignal(unsigned int newCode, int newVal);

protected:
     virtual void run();

private:
    void buzzer_huatu_Loop();
    void key_sig_run(char* pBuf,unsigned int len);
    void initialLedOutput_huatu();
    void initialKey_huatu();
    void setMsg(QString msg);
    int  key(void);
    int key_huatu_loop();



private:
    int keyFd;
    int outputFd;
    QString Msg;
    QReadWriteLock lock;
    int buttons_fd;// the file descriptor of the buttons device
    //key keyval =100;
    volatile bool isRun;
    //CustomToolDefine *m_pCustomInstace;
    unsigned int outputValue[1];
    int isBuzzerCount;

};

#endif // THREADDEV_H
